a11y: Refactor code
authorJoanmarie Diggs <jdiggs@igalia.com>
Wed, 25 Mar 2015 02:57:45 +0000 (03:57 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 25 Mar 2015 03:06:23 +0000 (04:06 +0100)
Put the equality check in front. This allows better detection of when an
insert or delete needs to be emitted.

Also, only emit text-changed:delete if the deleted text is not the empty
string. Only emit text-changed:insert if the inserted text is not the
empty string.

https://bugzilla.gnome.org/show_bug.cgi?id=746706

gtk/a11y/gtktextcellaccessible.c

index 1b68c9440add505a3ff7bd21aaf0fad8dd482b4b..8ea2d277cf299cd872f648b019d7a0755f2b673c 100644 (file)
@@ -136,7 +136,6 @@ gtk_text_cell_accessible_update_cache (GtkCellAccessible *cell)
 {
   GtkTextCellAccessible *text_cell = GTK_TEXT_CELL_ACCESSIBLE (cell);
   AtkObject *obj = ATK_OBJECT (cell);
-  gboolean rv = FALSE;
   gint temp_length, text_length;
   gchar *text;
   GtkCellRenderer *renderer;
@@ -153,9 +152,9 @@ gtk_text_cell_accessible_update_cache (GtkCellAccessible *cell)
     text = g_strdup ("");
   text_length = g_utf8_strlen (text, -1);
 
-  if (text_cell->priv->cell_text)
+  if (g_strcmp0 (text_cell->priv->cell_text, text) != 0)
     {
-      if (text == NULL || g_strcmp0 (text_cell->priv->cell_text, text) != 0)
+      if (text_cell->priv->cell_length)
         {
           g_free (text_cell->priv->cell_text);
           temp_length = text_cell->priv->cell_length;
@@ -164,29 +163,22 @@ gtk_text_cell_accessible_update_cache (GtkCellAccessible *cell)
           g_signal_emit_by_name (cell, "text-changed::delete", 0, temp_length);
           if (obj->name == NULL)
             g_object_notify (G_OBJECT (obj), "accessible-name");
-          if (text)
-            rv = TRUE;
         }
-    }
-  else
-    rv = TRUE;
 
-  if (rv)
-    {
       text_cell->priv->cell_text = g_strdup (text);
       text_cell->priv->cell_length = text_length;
-    }
 
-  g_free (text);
-
-  if (rv)
-    {
-      g_signal_emit_by_name (cell, "text-changed::insert",
-                             0, text_cell->priv->cell_length);
+      if (text_length)
+        {
+          g_signal_emit_by_name (cell, "text-changed::insert",
+                                 0, text_cell->priv->cell_length);
 
-      if (obj->name == NULL)
-        g_object_notify (G_OBJECT (obj), "accessible-name");
+          if (obj->name == NULL)
+            g_object_notify (G_OBJECT (obj), "accessible-name");
+        }
     }
+
+  g_free (text);
 }
 
 static void